package com.bening.smsapp.filechangereg;

import com.bening.smsapp.bootstrap.BootConfigParameters;
import com.bening.smsapp.constant.PropertiesConstant;

import org.apache.log4j.Logger;


public class FileChangeRegDaemon implements Runnable
{
    private static BootConfigParameters params;
    
    long interval = 300000; // default 300,000 milliseconds = 5  minutes

    public static void main( String[] args )
    {
        final Logger logger = Logger.getLogger( FileChangeRegDaemon.class );
        params = BootConfigParameters.getInstance();

        FileChangeRegDaemon daemon = new FileChangeRegDaemon();
        Thread thread = new Thread( daemon );
        String interval = params.getRegisterProperties().getProperty(PropertiesConstant.CORE_MAX_INTERVAL);
        daemon.setInterval( Long.valueOf(interval).longValue() );
        if ( logger.isInfoEnabled() )
        {
            logger.info( "starting daemon thread." );
        }
        thread.start();
    }

    /**
     * starting point of the worker thread.
     */
    public void run()
    {
        final Logger logger = Logger.getLogger( getClass() );
        final String METHOD_SIGNATURE = "[filechangereg]";

        while( true )
        {
            try
            {
                FileChangeProcess.process( params ); 
                Thread.sleep( interval );
            }
            catch( InterruptedException e )
            {
                logger.error( METHOD_SIGNATURE + e.getClass() + ": " + e.getMessage(), e );
            }
            catch( Exception e )
            {
                logger.error( METHOD_SIGNATURE + e.getClass() + ": " + e.getMessage(), e );
            }
            catch( Throwable t )
            {
            	
            }
            finally
            {
            	
            }
        }
    }


    public long getInterval()
    {
        return interval;
    }

    public void setInterval( long interval )
    {
        this.interval = interval;
    }

    
    
}
